package com.ag.dgm.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbPlanScope;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;

import com.ag.dgm.service.PlanScopeService;

@Controller("PlanScopeAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class PlanScopeAction extends BaseAction {
	private static final long serialVersionUID = 632320156208879217L;

	@Resource(name="planScopeService")
	private PlanScopeService planScopeService;
	private List<TbPlanScope> tbPlanScopeList;
	private String Id;
	private String Name;
	private String Detail;
	private String result;
	TbPlanScope tbPlanScope = new TbPlanScope();

	
	
	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}



	public void setTbPlanScopeList(List<TbPlanScope> tbPlanScopeList) {
		this.tbPlanScopeList = tbPlanScopeList;
	}


	public List<TbPlanScope> getTbPlanScopeList() {
		return tbPlanScopeList;
	}

	public String getId() {
		return Id;
	}

	public void setId(String Id) {
		this.Id = Id;
	}

	public String getName() {
		return Name;
	}

	public void setName(String Name) {
		this.Name = Name;
	}

	public String getDetail() {
		return Detail;
	}

	public void setDetail(String Detail) {
		this.Detail = Detail;
	}
	
	
	public String find() {
		tbPlanScopeList = planScopeService.findAll();
		return "main";
	}

	public String modify() {
		tbPlanScope.setPsId(Id);
		tbPlanScope.setPsDetail(Detail);
		tbPlanScope.setPsName(Name);
		tbPlanScope.setA(IDUtil.PRESERVE);
		this.setResult("修改成功");
		try {
			planScopeService.modify(tbPlanScope);
		} catch (Exception e) {
			this.setResult("修改不成功");
		}
		return "modify_succ";
		
	}

	public String delete() {
		tbPlanScope.setPsId(Id);
		this.setResult("删除成功");
	
			try {
				planScopeService.delete(tbPlanScope);
			} catch (Exception e) {
				e.printStackTrace();
			}
		return "delete_succ";
	}

	public String add() {
		tbPlanScope.setPsDetail(Detail);
		tbPlanScope.setPsName(Name);
		tbPlanScope.setA(IDUtil.PRESERVE);
		this.setResult("增加成功");
		try {
			planScopeService.add(tbPlanScope);
		} catch (Exception e) {
			this.setResult("增加不成功");
		}
		return "add_succ";	
	}

}
